home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / turbotut.arc / LIST2.PAS < prev    next >
Pascal/Delphi Source File  |  1989-06-30  |  4KB  |  120 lines

  1. PROGRAM list_pascal_source_files;
  2.  
  3. CONST max_lines_per_page = 50;
  4.  
  5.                 (* Note; This will not compile if you are using
  6.                    TURBO Pascal 2.0. Change the definitions for
  7.                    "file_to_print" and "input_line" to STRING[25]
  8.                    and STRING[140] to allow this program to
  9.                    compile with TURBO Pascal 2.0, since READ and
  10.                    READLN do not work with ARRAY OF CHAR.     *)
  11.  
  12. VAR input_file      : TEXT;
  13.     file_to_print   : ARRAY[1..25] OF CHAR;
  14.     input_line      : ARRAY[1..140] OF CHAR;
  15.     line_number     : INTEGER;
  16.     lines_printed   : INTEGER;
  17.     page_no         : INTEGER;
  18.     index           : INTEGER;
  19.  
  20. PROCEDURE initialize; (* ****************************** initialize *)
  21. BEGIN
  22.   WRITE('Enter filename ');
  23.   READLN(file_to_print);
  24.   ASSIGN(input_file,file_to_print);
  25.   RESET(input_file);
  26.   line_number := 1;
  27.   lines_printed := 66; (* This is to force a header immediately *)
  28.   page_no := 1;
  29. END;
  30.  
  31. PROCEDURE read_a_line; (* **************************** read a line *)
  32. BEGIN
  33.   FOR index := 1 TO 140 DO input_line[index] := ' ';
  34.   READLN(input_file,input_line);
  35. END;
  36.  
  37. PROCEDURE format_and_display; (* **************** format and display *)
  38.  
  39. VAR line_length : BYTE;
  40.  
  41. BEGIN
  42.   WRITE(line_number:6,'  ');
  43.     FOR index := 1 TO 140 DO
  44.     BEGIN
  45.       IF input_line[index] <> ' ' THEN line_length := index;
  46.     END;
  47.   IF line_length <= 70 THEN
  48.     BEGIN               (* line length less than 70 characters *)
  49.       FOR index := 1 TO line_length DO
  50.         WRITE(input_line[index]);
  51.       WRITELN;
  52.     END
  53.   ELSE
  54.     BEGIN               (* line length more than 70 characters *)
  55.       FOR index := 1 TO 70 DO
  56.         WRITE(input_line[index]);
  57.       WRITELN('<');
  58.       WRITE('        ');
  59.       FOR index := 71 TO line_length DO
  60.         WRITE(input_line[index]);
  61.       WRITELN;
  62.     END;
  63. END;
  64.  
  65. PROCEDURE format_and_print; (* ****************** format and print *)
  66.  
  67. VAR line_length : BYTE;
  68.  
  69. BEGIN
  70.   WRITE(lst,line_number:6,'  ');
  71.     FOR index := 1 TO 140 DO
  72.     BEGIN
  73.       IF input_line[index] <> ' ' THEN line_length := index;
  74.     END;
  75.   IF line_length <= 70 THEN
  76.     BEGIN               (* line length less than 70 characters *)
  77.       FOR index := 1 TO line_length DO
  78.         WRITE(lst,input_line[index]);
  79.       WRITELN(lst);
  80.       lines_printed := lines_printed + 1;
  81.     END
  82.   ELSE
  83.     BEGIN               (* line length more than 70 characters *)
  84.       FOR index := 1 TO 70 DO
  85.         WRITE(lst,input_line[index]);
  86.       WRITELN(lst,'<');
  87.       WRITE(lst,'        ');
  88.       FOR index := 71 TO line_length DO
  89.         WRITE(lst,input_line[index]);
  90.       WRITELN(lst);
  91.       lines_printed := lines_printed + 2;
  92.     END;
  93.   line_number := line_number + 1;
  94. END;
  95.  
  96. PROCEDURE check_for_page; (* ********************** check for page *)
  97. BEGIN
  98.   IF lines_printed > Max_lines_per_page THEN
  99.   BEGIN
  100.     IF page_no > 1 THEN WRITELN(lst,char(12));
  101.     FOR index := 1 TO 3 DO WRITELN(lst);
  102.     WRITE(lst,'     ');
  103.     WRITELN(lst,'Source file ',file_to_print,'Page':24,page_no:4);
  104.     page_no := page_no + 1;
  105.     lines_printed := 1;
  106.     WRITELN(lst);
  107.   END;
  108. END;
  109.  
  110. BEGIN  (* ******************************************* main program *)
  111.   initialize;
  112.   check_for_page;
  113.   REPEAT
  114.     read_a_line;
  115.     format_and_display;
  116.     format_and_print;
  117.     check_for_page;
  118.   UNTIL eof(input_file);
  119.   WRITELN(lst,char(12));
  120. END.  (* of main program *)